package org.raymond.iworks.repository.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
// 标注为@MappedSuperclass的类将不是一个完整的实体类，不会映射到数据库表，但是它的属性都将映射到子类的数据库字段中
@MappedSuperclass
// 开启自动审计
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}) //直接使用bean时，避免json序列号失败
public abstract class AbstractEntity implements Serializable {
    protected final static String ID_GENERATOR = "org.raymond.iworks.repository.utils.SnowIdGenerator";
    protected final static String ID_GENERATOR_NAME = "ID_GENERATOR";

    @CreatedDate
    private Date createTime;

    @CreatedBy
    private Long createBy;

    @LastModifiedDate
    private Date updateTime;

    @LastModifiedBy
    private Long updateBy;
}
